package main

import "fmt"

func main() {
	nums := []int{2, 2, 1}
	fmt.Println(thirdMax(nums))
}

/**
 * @Description: 用map来去重 用三个变量表示
 */
//#link: https://leetcode-cn.com/problems/third-maximum-number/
func thirdMax(nums []int) int {
	minNum := -1 << 31
	first, second, third := minNum, minNum, minNum
	numsMap := make(map[int]bool)
	for i := 0; i < len(nums); i++ {
		if _, ok := numsMap[nums[i]]; ok {
			continue
		}
		numsMap[nums[i]] = true
		if nums[i] > first {
			first, second, third = nums[i], first, second
			continue
		} else if nums[i] > second {
			second, third = nums[i], second
			continue
		} else if nums[i] > third {
			third = nums[i]
			continue
		}
	}
	if third != minNum {
		return third
	} else {
		return first
	}
}
